package com.hrm.service.impl;

import com.hrm.dao.EmpSalaryMapper;
import com.hrm.dto.EmpSalaryDTO;
import com.hrm.dto.EmpSalaryRecordDTO;
import com.hrm.service.EmpSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Auther: 朱晓龙
 * @Date: 2020/6/1 21:12
 * @Description: 员工薪酬管理接口实现
 */
@Service
public class EmpSalaryServiceImp implements EmpSalaryService {

    @Autowired
    private EmpSalaryMapper empSalaryMapper;

    @Override
    public List<EmpSalaryDTO> empSalaryList() {
        return empSalaryMapper.empSalaryList();
    }

    @Override
    public boolean updateSalaryPayTimeInfo(Integer salaryId, Integer payTime) {
        int updateLine = empSalaryMapper.updatePayTime(salaryId, payTime);
        return updateLine != 0;
    }

    @Override
    public boolean updateBasicSalary(Integer id, Integer basicSalary) {
        int updateLine = empSalaryMapper.updateBasicSalary(id, basicSalary);
        return updateLine != 0;
    }

    @Override
    public List<EmpSalaryRecordDTO> recordList(Integer id) {
        return empSalaryMapper.recordList(id);
    }

    @Override
    public boolean delSalaryRecord(EmpSalaryRecordDTO recordDTO) {
        int delLine = empSalaryMapper.delSalaryRecord(recordDTO);
        int delLine2 = empSalaryMapper.delBonusOrDeduct(recordDTO);
        return delLine != 0 && delLine2 != 0;
    }

    @Override
    public boolean addRecord(EmpSalaryRecordDTO recordDTO) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        recordDTO.setDate(df.format(new Date()));

        int addLine = empSalaryMapper.addRecord(recordDTO);
        int updateLine = empSalaryMapper.updateBonusOrDeduct(recordDTO);
        return addLine != 0 && updateLine != 0;
    }
}
